import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    baseUrl: "https://shslqxh.1meeting.com/", // 默认前端地址
    baseAPIUrl: "https://shslqxh.1meeting.com/api", // 默认后端地址
    // 基本信息
    loginToken: JSON.parse(localStorage.getItem("ADMIN_LOGINTOKEN")) || "", // 登录验证token
    loginUserId: JSON.parse(localStorage.getItem("ADMIN_LOGINUSERID")) || "", // 登录用户id
    loginUserName:
      JSON.parse(localStorage.getItem("ADMIN_LOGINUSERNAME")) || "", // 登录用户名

    // 页面缓存
    levelManagerParams:
      JSON.parse(localStorage.getItem("ADMIN_LEVELMANAGERPARAMS")) || {}, // 等级管理传参
    examManagerParams:
      JSON.parse(localStorage.getItem("ADMIN_EXAMMANAGERPARAMS")) || {}, // 科目管理传参
    orderDetailParams:
      JSON.parse(localStorage.getItem("ADMIN_ORDERDETAILPARAMS")) || {}, // 订单详情传参
    examineeDetailParams:
      JSON.parse(localStorage.getItem("ADMIN_EXAMINEEDETAILPARAMS")) || {}, // 考生详情传参
    examinerManagerParams:
      JSON.parse(localStorage.getItem("ADMIN_EXAMINERMANAGERPARAMS")) || {}, // 管理员管理传参
  },
  mutations: {
    // 更新token
    set_loginToken(state, value) {
      state.loginToken = value;
      if (value != "") {
        localStorage.setItem("ADMIN_LOGINTOKEN", JSON.stringify(value));
      } else {
        localStorage.removeItem("ADMIN_LOGINTOKEN");
      }
    },
    // 更新登录id
    set_loginUserId(state, value) {
      state.loginUserId = value;
      if (value != "") {
        localStorage.setItem("ADMIN_LOGINUSERID", JSON.stringify(value));
      } else {
        localStorage.removeItem("ADMIN_LOGINUSERID");
      }
    },
    // 更新登录用户名
    set_loginUserName(state, value) {
      state.loginUserName = value;
      if (value != "") {
        localStorage.setItem("ADMIN_LOGINUSERNAME", JSON.stringify(value));
      } else {
        localStorage.removeItem("ADMIN_LOGINUSERNAME");
      }
    },

    // 更新等级管理传参
    set_levelManagerParams(state, value) {
      state.levelManagerParams = value;
      localStorage.setItem("ADMIN_LEVELMANAGERPARAMS", JSON.stringify(value));
    },
    // 更新科目管理传参
    set_examManagerParams(state, value) {
      state.examManagerParams = value;
      localStorage.setItem("ADMIN_EXAMMANAGERPARAMS", JSON.stringify(value));
    },
    // 更新订单详情传参
    set_orderDetailParams(state, value) {
      state.orderDetailParams = value;
      localStorage.setItem("ADMIN_ORDERDETAILPARAMS", JSON.stringify(value));
    },
    // 更新考生详情传参
    set_examineeDetailParams(state, value) {
      state.examineeDetailParams = value;
      localStorage.setItem("ADMIN_EXAMINEEDETAILPARAMS", JSON.stringify(value));
    },
    // 更新管理员管理传参
    set_examinerManagerParams(state, value) {
      state.examinerManagerParams = value;
      localStorage.setItem(
        "ADMIN_EXAMINERMANAGERPARAMS",
        JSON.stringify(value)
      );
    },
  },
  actions: {},
  modules: {},
});
